package com.sky.tool;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class MultipartFileUtil {
    public static boolean transferTo(String fileParentPath, MultipartFile uploadFile) {
        try {
            String originalFilename = uploadFile.getOriginalFilename();
            File file = new File(fileParentPath + UUID.randomUUID() + originalFilename.substring(originalFilename.lastIndexOf(".")));
            if (!file.getParentFile().exists())
                file.getParentFile().mkdir();
            if (!file.exists())
                file.createNewFile();
            uploadFile.transferTo(file);
            System.out.println(file.getName() + "上传完成！");
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}
